package com.aya.tb;

import org.springframework.stereotype.Service;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;

@Service
public class StandardProcessorResolver implements ProcessorResolver {
    private final int OFFSET_INDEX = 2;
    public CodeProcessor resolve(byte[] msg) throws IOException {
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(msg);
        DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
        short code= dataInputStream.readShort();
        byte [] body = new byte[msg.length-OFFSET_INDEX];
        dataInputStream.read(body,0,body.length);

        StandardCodeProcessor codeProcessor = new StandardCodeProcessor(code,body);
        return codeProcessor;
    }
}
